﻿import QtQuick 2.15
import QtQuick.Controls 2.15

/*
  打印机设置界面
*/

Item {
    id:backGround
    width: screenWidth
    height: 1600

    Rectangle{
        anchors.fill: backGround
        color: "#00BFFF"
        border.width: 5
        border.color: "#F0F8FF"
    }

    onVisibleChanged: {
        if(visible === true)
        {
            Cpp_Connect.pageNumber = 12
        }
    }

    Rectangle{
        anchors.top: backGround.top
        anchors.horizontalCenter: backGround.horizontalCenter
        color: "#00BFFF"
        border.width: 5
        border.color: "#F0F8FF"
        width: backGround.width
        height: 750

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.top: parent.top
            anchors.topMargin: 35
            font.pixelSize: 30
            font.bold: true
            text: qsTr("型材长度:")
        }

        MyShowInput{        // 型材长度打印
            id: print_Length
            anchors.left: parent.left
            anchors.leftMargin: 180
            anchors.top: parent.top
            anchors.topMargin: 15
            showWidth: 400
            showHeight: 70
            maxShowLength: 20
        }


        Text{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.top: parent.top
            anchors.topMargin: 120
            font.pixelSize: 30
            font.bold: true
            text: qsTr("型材高度:")
        }

        MyShowInput{        // 型材高度打印
            id: print_Height
            anchors.left: parent.left
            anchors.leftMargin: 180
            anchors.top: parent.top
            anchors.topMargin: 100
            showWidth: 400
            showHeight: 70
            maxShowLength: 20
        }

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.top: parent.top
            anchors.topMargin: 210
            font.pixelSize: 30
            font.bold: true
            text: qsTr("左角度:")
        }

        MyShowInput{        // 左角度打印
            id: print_LeftAngle
            anchors.left: parent.left
            anchors.leftMargin: 180
            anchors.top: parent.top
            anchors.topMargin: 190
            showWidth: 200
            showHeight: 70
            maxShowLength: 10
        }

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.top: parent.top
            anchors.topMargin: 300
            font.pixelSize: 30
            font.bold: true
            text: qsTr("右角度:")
        }

        MyShowInput{        // 右角度打印
            id: print_RightAngle
            anchors.left: parent.left
            anchors.leftMargin: 180
            anchors.top: parent.top
            anchors.topMargin: 280
            showWidth: 200
            showHeight: 70
            maxShowLength: 20
        }

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.top: parent.top
            anchors.topMargin: 390
            font.pixelSize: 30
            font.bold: true
            text: qsTr("客户名称:")
        }

        MyShowInput{        // 客户名称打印
            id:print_Custom
            anchors.left: parent.left
            anchors.leftMargin: 180
            anchors.top: parent.top
            anchors.topMargin: 370
            showWidth: 400
            showHeight: 70
            maxShowLength: 20
        }

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.top: parent.top
            anchors.topMargin: 480
            font.pixelSize: 30
            font.bold: true
            text: qsTr("型材名称:")
        }

        MyShowInput{        // 型材名称打印
            id:print_MaterialName
            anchors.left: parent.left
            anchors.leftMargin: 180
            anchors.top: parent.top
            anchors.topMargin: 460
            showWidth: 400
            showHeight: 70
            maxShowLength: 20
        }

        Text{
            anchors.right: parent.right
            anchors.rightMargin: 320
            anchors.top: parent.top
            anchors.topMargin: 40
            font.pixelSize: 30
            font.bold: true
            text:qsTr("二维码类型")
        }

        ComboBox{       // 二维码类型选择
            id:printerType
            anchors.right: parent.right
            anchors.rightMargin: 20
            anchors.top: parent.top
            anchors.topMargin: 20
            width: 270
            height: 60
            model:["瑞工RG-EL58","炜煌P16-20"]
            currentIndex: 0

            contentItem: Text {     //界面上显示出来的文字
                leftPadding: 20      //左部填充为5
                text: printerType.displayText   //表示ComboBox上显示的文本
                // font: printerType.font          //文字大小
                font.pixelSize: 30
                color: printerType.enabled ? "black" : "grey"   //printerType.pressed ?
                verticalAlignment: Text.AlignVCenter        //文字位置
            }

            background: Rectangle {   //背景项
                implicitWidth: 120
                implicitHeight: 60
                property string sColor: printerType.enabled ? "white" : "lightgrey"
                color: printerType.pressed ? Qt.darker(sColor, 1.2) : sColor
                border.width: 1
                border.color: "lightgrey"
                radius: 0
            }


            onActivated: {
                console.log(currentText)
            }
        }      
    }


    Rectangle{
        anchors.top: backGround.top
        anchors.topMargin: 745
        anchors.horizontalCenter: backGround.horizontalCenter
        color: "#00BFFF"
        border.width: 5
        border.color: "#F0F8FF"
        width: backGround.width
        height: 150

        Rectangle{
            anchors.verticalCenter: parent.verticalCenter
            anchors.left: parent.left
            anchors.leftMargin: 30
            width: 200
            height: 100
            radius: 10
            color: "#006cee"
            border.width: 1
            border.color: "#f0f8ff"

            Text{
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                text: qsTr("手动打印")
            }

            MouseArea{
                anchors.fill: parent

                onPressed: {
                    parent.color = "#ff3606"
                    parent.forceActiveFocus()
                    if( printerType.currentIndex === 0 )
                    {
                        console.log("当前打印动作 -- 瑞工打印机")
                        Cpp_Connect.printerMethod(true,
                                                  print_Length.printData,
                                                  print_Height.printData,
                                                  print_LeftAngle.printData,
                                                  print_RightAngle.printData,
                                                  print_Custom.printData,
                                                  print_MaterialName.printData)
                    }
                    else if( printerType.currentIndex === 1 )
                    {
                        console.log("当前打印动作 -- 炜煌打印机")
                        Cpp_Connect.printerMethod(false,
                                                  print_Length.printData,
                                                  print_Height.printData,
                                                  print_LeftAngle.printData,
                                                  print_RightAngle.printData,
                                                  print_Custom.printData,
                                                  print_MaterialName.printData)
                    }
                }

                onReleased: {
                    parent.color = "#006cee"
                }
            }
        }


        Rectangle{      // 自动打印功能是否启用
            anchors.verticalCenter: parent.verticalCenter
            anchors.left: parent.left
            anchors.leftMargin: 310
            width: 400
            height: 100
            radius: 10
            color: flag ?  "#ff3606" : "#006cee"
            border.width: 1
            border.color: "#f0f8ff"
            visible: false

            property bool flag: Cpp_Connect.AutoPrint

            Text{
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                text: parent.flag ? qsTr("自动打印已启用") : qsTr("自动打印已关闭")
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    parent.forceActiveFocus()

                    if(!parent.flag)
                    {
                        Cpp_Connect.write_modbus_rtu_Coils("511","1")
                    }
                    else
                    {
                        Cpp_Connect.write_modbus_rtu_Coils("511","0")
                    }
                }
            }
        }


    }

}
